package com.jic.member.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.member.entity.MememberIntegralOrderRecharge;
import com.jic.member.mapper.MememberIntegralOrderRechargeMapper;
import com.jic.member.service.MememberIntegralOrderRechargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员积分规则下单-充值赠送表
 * @author : 
 * @email : 
 * @since : 2020-04-02 03:34:47
 * @version : v1.0.0
 */
@Service
public class MememberIntegralOrderRechargeServiceImpl implements MememberIntegralOrderRechargeService {

    @Autowired
    private MememberIntegralOrderRechargeMapper mememberIntegralOrderRechargeMapper;

    @Override
    public long insert(MememberIntegralOrderRecharge mememberIntegralOrderRecharge) {
        long flag = mememberIntegralOrderRechargeMapper.insert(mememberIntegralOrderRecharge);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return mememberIntegralOrderRechargeMapper.delete(id);
    }

    @Override
    public long update(MememberIntegralOrderRecharge mememberIntegralOrderRecharge) {
        long flag =0;
        if (mememberIntegralOrderRecharge.getId() !=null){
            flag = mememberIntegralOrderRechargeMapper.update(mememberIntegralOrderRecharge);
        }else {
            mememberIntegralOrderRechargeMapper.insert(mememberIntegralOrderRecharge);
        }
        return flag;
    }

    @Override
    public MememberIntegralOrderRecharge queryByPrimaryKey(Long orderRechargeId){
        return mememberIntegralOrderRechargeMapper.queryByPrimaryKey(orderRechargeId);
    }

    @Override
    public List<MememberIntegralOrderRecharge> query(MememberIntegralOrderRecharge mememberIntegralOrderRecharge){
        return mememberIntegralOrderRechargeMapper.query(mememberIntegralOrderRecharge);
    }

    @Override
    public PageResult<MememberIntegralOrderRecharge> queryPage(MememberIntegralOrderRecharge mememberIntegralOrderRecharge, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<MememberIntegralOrderRecharge> list = mememberIntegralOrderRechargeMapper.queryPage(startIndex, pageQuery.getLimit(), mememberIntegralOrderRecharge);
        long count = mememberIntegralOrderRechargeMapper.queryPageCount(mememberIntegralOrderRecharge);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}